package JDBCTest;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;


public class TestDelete {
    public static void main(String[] args) throws SQLException {
        // 创建数据源对象
        MysqlDataSource mysqlDataSource = new MysqlDataSource();

        // 进行准备工作
        // 确实服务器地址
        mysqlDataSource.setURL("jdbc:mysql://127.0.0.1:3306/java112?characterEncoding=utf8&useSSL=false");
        mysqlDataSource.setUser("root");
        mysqlDataSource.setPassword("q20031229");

        // 进行网络连接
       Connection connection = mysqlDataSource.getConnection();

       // 创建SQL语句
        String sql = "delete from test where id = 19 ";

        // 进行预编译
       PreparedStatement preparedStatement = connection.prepareStatement(sql);

       // 执行到服务器
        preparedStatement.executeUpdate();

        // 释放资源
        preparedStatement.close();
        connection.close();
    }
}
